﻿/**  版本信息模板在安装目录下，可自行修改。
* hars_costlist.cs
*
* 功 能： N/A
* 类 名： hars_costlist
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2017/12/8 21:15:11   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;

namespace PreeRegisterDAL
{
    /// <summary>
    /// 数据访问类:hars_costlist
    /// </summary>
    public partial class hars_costlist
    {
        public hars_costlist()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperMySQL.GetMaxID("uid", "hars_costlist");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int uid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from hars_costlist");
            strSql.Append(" where uid=@uid");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@uid", MySqlDbType.Int32)
            };
            parameters[0].Value = uid;

            return DbHelperMySQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(PreeRegisterModel.hars_costlist model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into hars_costlist(");
            strSql.Append("pid,PatientCode,HospitaliezdTimes,PatientName,Id,FeeDateTime,FeeCode,FeeName,Unit,Count,Price,Amount,createdate,PrescriptionCode,OpenDeptCode,OpenDeptName,OpenDoctorCode,OpenDoctorName,ReceiveDeptCode,ReceiveDeptName,ReceiveDoctorCode,OperatorCode,OperatorName,RefundOperatorCode,RefundOperatorName,RefundDatetime,RefundReason,BelongDeptCode,BelongDeptName,BatchCode,Specification,DrugStoreCode,DrugStoreName,TradePrice,FirstItemCode,AdviceId,ApplicationCode)");
            strSql.Append(" values (");
            strSql.Append("@pid,@PatientCode,@HospitaliezdTimes,@PatientName,@Id,@FeeDateTime,@FeeCode,@FeeName,@Unit,@Count,@Price,@Amount,@createdate,@PrescriptionCode,@OpenDeptCode,@OpenDeptName,@OpenDoctorCode,@OpenDoctorName,@ReceiveDeptCode,@ReceiveDeptName,@ReceiveDoctorCode,@OperatorCode,@OperatorName,@RefundOperatorCode,@RefundOperatorName,@RefundDatetime,@RefundReason,@BelongDeptCode,@BelongDeptName,@BatchCode,@Specification,@DrugStoreCode,@DrugStoreName,@TradePrice,@FirstItemCode,@AdviceId,@ApplicationCode)");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@pid", MySqlDbType.VarChar,50),
                    new MySqlParameter("@PatientCode", MySqlDbType.VarChar,50),
                    new MySqlParameter("@HospitaliezdTimes", MySqlDbType.VarChar,5),
                    new MySqlParameter("@PatientName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@Id", MySqlDbType.VarChar,200),
                    new MySqlParameter("@FeeDateTime", MySqlDbType.VarChar,30),
                    new MySqlParameter("@FeeCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@FeeName", MySqlDbType.VarChar,1000),
                    new MySqlParameter("@Unit", MySqlDbType.VarChar,200),
                    new MySqlParameter("@Count", MySqlDbType.VarChar,200),
                    new MySqlParameter("@Price", MySqlDbType.VarChar,200),
                    new MySqlParameter("@Amount", MySqlDbType.VarChar,200),
                    new MySqlParameter("@createdate", MySqlDbType.Timestamp),
                    new MySqlParameter("@PrescriptionCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OpenDeptCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OpenDeptName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OpenDoctorCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OpenDoctorName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@ReceiveDeptCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@ReceiveDeptName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@ReceiveDoctorCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OperatorCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OperatorName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@RefundOperatorCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@RefundOperatorName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@RefundDatetime", MySqlDbType.VarChar,200),
                    new MySqlParameter("@RefundReason", MySqlDbType.VarChar,200),
                    new MySqlParameter("@BelongDeptCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@BelongDeptName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@BatchCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@Specification", MySqlDbType.VarChar,200),
                    new MySqlParameter("@DrugStoreCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@DrugStoreName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@TradePrice", MySqlDbType.VarChar,200),
                    new MySqlParameter("@FirstItemCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@AdviceId", MySqlDbType.VarChar,200),
                    new MySqlParameter("@ApplicationCode", MySqlDbType.VarChar,200)};
            parameters[0].Value = model.pid;
            parameters[1].Value = model.PatientCode;
            parameters[2].Value = model.HospitaliezdTimes;
            parameters[3].Value = model.PatientName;
            parameters[4].Value = model.Id;
            parameters[5].Value = model.FeeDateTime;
            parameters[6].Value = model.FeeCode;
            parameters[7].Value = model.FeeName;
            parameters[8].Value = model.Unit;
            parameters[9].Value = model.Count;
            parameters[10].Value = model.Price;
            parameters[11].Value = model.Amount;
            parameters[12].Value = model.createdate;
            parameters[13].Value = model.PrescriptionCode;
            parameters[14].Value = model.OpenDeptCode;
            parameters[15].Value = model.OpenDeptName;
            parameters[16].Value = model.OpenDoctorCode;
            parameters[17].Value = model.OpenDoctorName;
            parameters[18].Value = model.ReceiveDeptCode;
            parameters[19].Value = model.ReceiveDeptName;
            parameters[20].Value = model.ReceiveDoctorCode;
            parameters[21].Value = model.OperatorCode;
            parameters[22].Value = model.OperatorName;
            parameters[23].Value = model.RefundOperatorCode;
            parameters[24].Value = model.RefundOperatorName;
            parameters[25].Value = model.RefundDatetime;
            parameters[26].Value = model.RefundReason;
            parameters[27].Value = model.BelongDeptCode;
            parameters[28].Value = model.BelongDeptName;
            parameters[29].Value = model.BatchCode;
            parameters[30].Value = model.Specification;
            parameters[31].Value = model.DrugStoreCode;
            parameters[32].Value = model.DrugStoreName;
            parameters[33].Value = model.TradePrice;
            parameters[34].Value = model.FirstItemCode;
            parameters[35].Value = model.AdviceId;
            parameters[36].Value = model.ApplicationCode;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PreeRegisterModel.hars_costlist model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update hars_costlist set ");
            strSql.Append("pid=@pid,");
            strSql.Append("PatientCode=@PatientCode,");
            strSql.Append("HospitaliezdTimes=@HospitaliezdTimes,");
            strSql.Append("PatientName=@PatientName,");
            strSql.Append("Id=@Id,");
            strSql.Append("FeeDateTime=@FeeDateTime,");
            strSql.Append("FeeCode=@FeeCode,");
            strSql.Append("FeeName=@FeeName,");
            strSql.Append("Unit=@Unit,");
            strSql.Append("Count=@Count,");
            strSql.Append("Price=@Price,");
            strSql.Append("Amount=@Amount,");
            strSql.Append("PrescriptionCode=@PrescriptionCode,");
            strSql.Append("OpenDeptCode=@OpenDeptCode,");
            strSql.Append("OpenDeptName=@OpenDeptName,");
            strSql.Append("OpenDoctorCode=@OpenDoctorCode,");
            strSql.Append("OpenDoctorName=@OpenDoctorName,");
            strSql.Append("ReceiveDeptCode=@ReceiveDeptCode,");
            strSql.Append("ReceiveDeptName=@ReceiveDeptName,");
            strSql.Append("ReceiveDoctorCode=@ReceiveDoctorCode,");
            strSql.Append("OperatorCode=@OperatorCode,");
            strSql.Append("OperatorName=@OperatorName,");
            strSql.Append("RefundOperatorCode=@RefundOperatorCode,");
            strSql.Append("RefundOperatorName=@RefundOperatorName,");
            strSql.Append("RefundDatetime=@RefundDatetime,");
            strSql.Append("RefundReason=@RefundReason,");
            strSql.Append("BelongDeptCode=@BelongDeptCode,");
            strSql.Append("BelongDeptName=@BelongDeptName,");
            strSql.Append("BatchCode=@BatchCode,");
            strSql.Append("Specification=@Specification,");
            strSql.Append("DrugStoreCode=@DrugStoreCode,");
            strSql.Append("DrugStoreName=@DrugStoreName,");
            strSql.Append("TradePrice=@TradePrice,");
            strSql.Append("FirstItemCode=@FirstItemCode,");
            strSql.Append("AdviceId=@AdviceId,");
            strSql.Append("ApplicationCode=@ApplicationCode");
            strSql.Append(" where uid=@uid");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@pid", MySqlDbType.VarChar,50),
                    new MySqlParameter("@PatientCode", MySqlDbType.VarChar,50),
                    new MySqlParameter("@HospitaliezdTimes", MySqlDbType.VarChar,5),
                    new MySqlParameter("@PatientName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@Id", MySqlDbType.VarChar,200),
                    new MySqlParameter("@FeeDateTime", MySqlDbType.VarChar,30),
                    new MySqlParameter("@FeeCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@FeeName", MySqlDbType.VarChar,1000),
                    new MySqlParameter("@Unit", MySqlDbType.VarChar,200),
                    new MySqlParameter("@Count", MySqlDbType.VarChar,200),
                    new MySqlParameter("@Price", MySqlDbType.VarChar,200),
                    new MySqlParameter("@Amount", MySqlDbType.VarChar,200),
                    new MySqlParameter("@PrescriptionCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OpenDeptCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OpenDeptName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OpenDoctorCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OpenDoctorName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@ReceiveDeptCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@ReceiveDeptName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@ReceiveDoctorCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OperatorCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@OperatorName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@RefundOperatorCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@RefundOperatorName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@RefundDatetime", MySqlDbType.VarChar,200),
                    new MySqlParameter("@RefundReason", MySqlDbType.VarChar,200),
                    new MySqlParameter("@BelongDeptCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@BelongDeptName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@BatchCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@Specification", MySqlDbType.VarChar,200),
                    new MySqlParameter("@DrugStoreCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@DrugStoreName", MySqlDbType.VarChar,200),
                    new MySqlParameter("@TradePrice", MySqlDbType.VarChar,200),
                    new MySqlParameter("@FirstItemCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@AdviceId", MySqlDbType.VarChar,200),
                    new MySqlParameter("@ApplicationCode", MySqlDbType.VarChar,200),
                    new MySqlParameter("@uid", MySqlDbType.Int32,50)};
            parameters[0].Value = model.pid;
            parameters[1].Value = model.PatientCode;
            parameters[2].Value = model.HospitaliezdTimes;
            parameters[3].Value = model.PatientName;
            parameters[4].Value = model.Id;
            parameters[5].Value = model.FeeDateTime;
            parameters[6].Value = model.FeeCode;
            parameters[7].Value = model.FeeName;
            parameters[8].Value = model.Unit;
            parameters[9].Value = model.Count;
            parameters[10].Value = model.Price;
            parameters[11].Value = model.Amount;
            parameters[12].Value = model.PrescriptionCode;
            parameters[13].Value = model.OpenDeptCode;
            parameters[14].Value = model.OpenDeptName;
            parameters[15].Value = model.OpenDoctorCode;
            parameters[16].Value = model.OpenDoctorName;
            parameters[17].Value = model.ReceiveDeptCode;
            parameters[18].Value = model.ReceiveDeptName;
            parameters[19].Value = model.ReceiveDoctorCode;
            parameters[20].Value = model.OperatorCode;
            parameters[21].Value = model.OperatorName;
            parameters[22].Value = model.RefundOperatorCode;
            parameters[23].Value = model.RefundOperatorName;
            parameters[24].Value = model.RefundDatetime;
            parameters[25].Value = model.RefundReason;
            parameters[26].Value = model.BelongDeptCode;
            parameters[27].Value = model.BelongDeptName;
            parameters[28].Value = model.BatchCode;
            parameters[29].Value = model.Specification;
            parameters[30].Value = model.DrugStoreCode;
            parameters[31].Value = model.DrugStoreName;
            parameters[32].Value = model.TradePrice;
            parameters[33].Value = model.FirstItemCode;
            parameters[34].Value = model.AdviceId;
            parameters[35].Value = model.ApplicationCode;
            parameters[36].Value = model.uid;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int uid)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from hars_costlist ");
            strSql.Append(" where uid=@uid");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@uid", MySqlDbType.Int32)
            };
            parameters[0].Value = uid;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string uidlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from hars_costlist ");
            strSql.Append(" where uid in (" + uidlist + ")  ");
            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PreeRegisterModel.hars_costlist GetModel(int uid)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select uid,pid,adnum,times,id,time,name,spec,count,sum,ext1,ext2,createdate from hars_costlist ");
            strSql.Append(" where uid=@uid");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@uid", MySqlDbType.Int32)
            };
            parameters[0].Value = uid;

            PreeRegisterModel.hars_costlist model = new PreeRegisterModel.hars_costlist();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PreeRegisterModel.hars_costlist DataRowToModel(DataRow row)
        {
            PreeRegisterModel.hars_costlist model = new PreeRegisterModel.hars_costlist();
            if (row != null)
            {
                if (row["uid"] != null && row["uid"].ToString() != "")
                {
                    model.uid = int.Parse(row["uid"].ToString());
                }
                if (row["pid"] != null)
                {
                    model.pid = row["pid"].ToString();
                }
                if (row["PatientCode"] != null)
                {
                    model.PatientCode = row["PatientCode"].ToString();
                }
                if (row["HospitaliezdTimes"] != null)
                {
                    model.HospitaliezdTimes = row["HospitaliezdTimes"].ToString();
                }
                if (row["PatientName"] != null)
                {
                    model.PatientName = row["PatientName"].ToString();
                }
                if (row["Id"] != null)
                {
                    model.Id = row["Id"].ToString();
                }
                if (row["FeeDateTime"] != null)
                {
                    model.FeeDateTime = row["FeeDateTime"].ToString();
                }
                if (row["FeeCode"] != null)
                {
                    model.FeeCode = row["FeeCode"].ToString();
                }
                if (row["FeeName"] != null)
                {
                    model.FeeName = row["FeeName"].ToString();
                }
                if (row["Unit"] != null)
                {
                    model.Unit = row["Unit"].ToString();
                }
                if (row["Count"] != null)
                {
                    model.Count = row["Count"].ToString();
                }
                if (row["Price"] != null)
                {
                    model.Price = row["Price"].ToString();
                }
                if (row["Amount"] != null)
                {
                    model.Amount = row["Amount"].ToString();
                }
                if (row["createdate"] != null && row["createdate"].ToString() != "")
                {
                    model.createdate = DateTime.Parse(row["createdate"].ToString());
                }
                if (row["PrescriptionCode"] != null)
                {
                    model.PrescriptionCode = row["PrescriptionCode"].ToString();
                }
                if (row["OpenDeptCode"] != null)
                {
                    model.OpenDeptCode = row["OpenDeptCode"].ToString();
                }
                if (row["OpenDeptName"] != null)
                {
                    model.OpenDeptName = row["OpenDeptName"].ToString();
                }
                if (row["OpenDoctorCode"] != null)
                {
                    model.OpenDoctorCode = row["OpenDoctorCode"].ToString();
                }
                if (row["OpenDoctorName"] != null)
                {
                    model.OpenDoctorName = row["OpenDoctorName"].ToString();
                }
                if (row["ReceiveDeptCode"] != null)
                {
                    model.ReceiveDeptCode = row["ReceiveDeptCode"].ToString();
                }
                if (row["ReceiveDeptName"] != null)
                {
                    model.ReceiveDeptName = row["ReceiveDeptName"].ToString();
                }
                if (row["ReceiveDoctorCode"] != null)
                {
                    model.ReceiveDoctorCode = row["ReceiveDoctorCode"].ToString();
                }
                if (row["OperatorCode"] != null)
                {
                    model.OperatorCode = row["OperatorCode"].ToString();
                }
                if (row["OperatorName"] != null)
                {
                    model.OperatorName = row["OperatorName"].ToString();
                }
                if (row["RefundOperatorCode"] != null)
                {
                    model.RefundOperatorCode = row["RefundOperatorCode"].ToString();
                }
                if (row["RefundOperatorName"] != null)
                {
                    model.RefundOperatorName = row["RefundOperatorName"].ToString();
                }
                if (row["RefundDatetime"] != null)
                {
                    model.RefundDatetime = row["RefundDatetime"].ToString();
                }
                if (row["RefundReason"] != null)
                {
                    model.RefundReason = row["RefundReason"].ToString();
                }
                if (row["BelongDeptCode"] != null)
                {
                    model.BelongDeptCode = row["BelongDeptCode"].ToString();
                }
                if (row["BelongDeptName"] != null)
                {
                    model.BelongDeptName = row["BelongDeptName"].ToString();
                }
                if (row["BatchCode"] != null)
                {
                    model.BatchCode = row["BatchCode"].ToString();
                }
                if (row["Specification"] != null)
                {
                    model.Specification = row["Specification"].ToString();
                }
                if (row["DrugStoreCode"] != null)
                {
                    model.DrugStoreCode = row["DrugStoreCode"].ToString();
                }
                if (row["DrugStoreName"] != null)
                {
                    model.DrugStoreName = row["DrugStoreName"].ToString();
                }
                if (row["TradePrice"] != null)
                {
                    model.TradePrice = row["TradePrice"].ToString();
                }
                if (row["FirstItemCode"] != null)
                {
                    model.FirstItemCode = row["FirstItemCode"].ToString();
                }
                if (row["AdviceId"] != null)
                {
                    model.AdviceId = row["AdviceId"].ToString();
                }
                if (row["ApplicationCode"] != null)
                {
                    model.ApplicationCode = row["ApplicationCode"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select uid,pid,PatientCode,HospitaliezdTimes,PatientName,Id,FeeDateTime,FeeCode,FeeName,Unit,Count,Price,Amount,createdate,PrescriptionCode,OpenDeptCode,OpenDeptName,OpenDoctorCode,OpenDoctorName,ReceiveDeptCode,ReceiveDeptName,ReceiveDoctorCode,OperatorCode,OperatorName,RefundOperatorCode,RefundOperatorName,RefundDatetime,RefundReason,BelongDeptCode,BelongDeptName,BatchCode,Specification,DrugStoreCode,DrugStoreName,TradePrice,FirstItemCode,AdviceId,ApplicationCode ");
            strSql.Append(" FROM hars_costlist ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperMySQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.uid desc");
            }
            strSql.Append(")AS Row, T.*  from hars_costlist T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperMySQL.Query(strSql.ToString());
        }


        #endregion  BasicMethod

        #region  ExtensionMethod

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from hars_costlist");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters = {
                new MySqlParameter("@id", MySqlDbType.VarChar)
            };
            parameters[0].Value = id;

            return DbHelperMySQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获取费用清单，含当日合计（以患者+清单日期为单位）
        /// </summary>
        /// <param name="pid">患者ID</param>
        /// <param name="date">日期为空，则返回截止到当前日期的费用清单，不为空，则返回指定日期的费用清单</param>
        /// <returns></returns>
        public DataSet GetList(string pid, string date)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select t.*,");
            strSql.Append("date_format(t.FeeDateTime, '%Y-%m-%d') AS days,");
            strSql.Append(" (select sum(Amount)");
            strSql.Append("  from hars_costlist");
            strSql.Append("  where pid = t.pid");
            strSql.Append("  and date_format(FeeDateTime, '%Y-%m-%d') =");
            strSql.Append("  date_format(t.FeeDateTime, '%Y-%m-%d')) AS total");
            strSql.Append(" from hars_costlist t");
            strSql.Append(" where 1 = 1");
            strSql.AppendFormat(" and t.pid = '{0}'", pid);
            if (!string.IsNullOrEmpty(date))
            {
                strSql.AppendFormat(" and date_format(t.FeeDateTime, '%Y-%m-%d') = '{0}'", date);
            }
            else
            {
                strSql.AppendFormat(" and date_format(t.FeeDateTime, '%Y-%m-%d') <= '{0}'"
               , DateTime.Now.AddDays(0).ToString("yyyy-MM-dd"));
            }

            return DbHelperMySQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取费用明细
        /// </summary>
        /// <param name="pid">患者ID</param>
        ///  <param name="date">日期为空，则返回截止到当前日期的费用明细，不为空，则返回指定日期的费用明细</param>
        /// <returns></returns>
        public DataSet GetCostDetial(string pid,  string date)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT sum(Amount) Amount, t.FeeName FROM   hars_costlist t");
            strSql.AppendFormat(" WHERE pid = '{0}'", pid);

            if (!string.IsNullOrEmpty(date))
            {
                strSql.AppendFormat(" and date_format(t.FeeDateTime, '%Y-%m-%d') = '{0}'", date);
            }
            else
            {
                strSql.AppendFormat(" and date_format(t.FeeDateTime, '%Y-%m-%d') <= '{0}'"
               , DateTime.Now.AddDays(0).ToString("yyyy-MM-dd"));
            }

            strSql.Append(" GROUP BY t.FeeName");
            strSql.Append(" ORDER BY sum(Amount) DESC");

            return DbHelperMySQL.Query(strSql.ToString());
        }

        #endregion  ExtensionMethod
    }
}

